package com.sunny.design.proxy.dynamicproxy.jdkproxy.exam2;

import com.sunny.design.proxy.IOrderService;
import com.sunny.design.proxy.Order;
import com.sunny.design.proxy.OrderService;
//import sun.misc.ProxyGenerator;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author Sunny
 * @date 2020/1/1 20:10
 */
public class Eaxm2DynamicProxyTest {
    public static void main(String[] args) {
        try {
            Order order = new Order();
//            order.setCreateTime(new Date().getTime());
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
            Date date = sdf.parse("2019/01/01");
            order.setCreateTime(date.getTime());

            OrderServiceDynamicProxy dynamicProxy = new OrderServiceDynamicProxy();
            IOrderService proxyInstance = (IOrderService) dynamicProxy.getInstance(new OrderService());
            proxyInstance.createOrder(order);

            //通过反编译工具可以查看生成的代理类源代码
            /*byte [] bytes = ProxyGenerator.generateProxyClass("$Proxy0",new Class[]{Person.class});
            FileOutputStream os = new FileOutputStream("E://$Proxy0.class");
            os.write(bytes);
            os.close();*/
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
